<template>
  <div>
    <!-- 面包屑 -->
    <div>
      <el-breadcrumb separator="/" class="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>设置</el-breadcrumb-item>
        <el-breadcrumb-item>优惠券管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-row class="elRow">
      <el-button
        @click="AddCoupon"
        type="primary"
        icon="el-icon-circle-plus-outline"
        >添加优惠券</el-button
      >
    </el-row>
    <!-- 列表 -->
    <div>
      <el-table :data="CouponList" border style="width: 100%" class="tableData">
        <el-table-column prop="type" label="类型" height="40">
        </el-table-column>
        <el-table-column prop="condition" height="30px" label="满减底线">
        </el-table-column>
        <el-table-column prop="value" height="30px" label="面值">
        </el-table-column>
        <el-table-column prop="createTime" height="30px" label="创建时间">
        </el-table-column>
        <el-table-column
          prop="expirationTime"
          height="30px"
          label="过期时间"
        ></el-table-column>
        <el-table-column prop="expirationTime" height="30px" label="操作">
          <template slot-scope="scope">
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
        </el-table-column>
      </el-table>
    </div>
    <!--  -->
    <el-dialog
      :visible.sync="dialogVisible"
      :before-close="handleClose"
      class="elDialog"
    >
      <i class="el-icon-warning"></i
      ><span>此操作将会删除数据,您仍然可通过回收站找回 是否继续?</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button height="50px" type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!--  -->
    <!-- 分页 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[3, 7, 10, 400]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="data.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions,mapState } = createNamespacedHelpers("CouponManagementList");
export default {
  data() {
    return {
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      dialogVisible: false,
    };
  },
  created() {
    this.CouponManagementListData(); 
  },
  computed:{
    ...mapState(['CouponList','data'])
    
  },
  methods: {
    ...mapActions(["CouponManagementListData","DeleteCouponId",'onshow','currentPage']),
    handleDelete(index, row) {
      console.log(index, row);
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.onshow(val)
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage(val)
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    // 跳转到新增优惠券
    AddCoupon() {
      this.$router.push({
        path: "/home/AddCouponManagementList",
      });
    },
    handleDelete(index, row) {
        console.log(index, row);
        this.DeleteCouponId(row.id)
      }
  },
};
</script>

<style scoped lang="scss">
.tableData {
  width: 100%;
}
.block {
  margin-top: 20px;
}
.elRow {
  height: 60px;
  line-height: 60px;
  text-align: right;
  margin-right: 100px;
}
</style>